package com.example.g7640.controller;


import com.example.g7640.builder.ResultBuilder;
import com.example.g7640.dto.ChangePasswordDto;
import com.example.g7640.dto.CustomerDto;
import com.example.g7640.dto.CustomerQuery;
import com.example.g7640.dto.common.PageResult;
import com.example.g7640.dto.common.Result;
import com.example.g7640.service.CustomerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author  
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/api/customer")
public class CustomerController {

    @Resource
    CustomerService customerService;


    @GetMapping("/get-info")
    public Result<CustomerDto> getInfo(Integer id){

        return ResultBuilder.buildSuccess(customerService.getCustomerDtoById(id));
    }


    @GetMapping("/get-list")
    public PageResult<List<CustomerDto>> getList(CustomerQuery customerQuery){
        return customerService.query(customerQuery);
    }

    @PostMapping("/change-password")
    public Result<String> updatePassword(@RequestBody ChangePasswordDto changePasswordDto){
        customerService.updatePassword(changePasswordDto);
        return ResultBuilder.buildSuccess(null);
    }

    @PostMapping("/set-password")
    public Result<String> resetPassword(@RequestBody CustomerDto customerDto){
        customerService.resetPassword(customerDto);
        return ResultBuilder.buildSuccess(null);
    }

    @GetMapping("/del")
    public Result<String> deleteCustomer(Integer id){
        customerService.deleteCustomer(id);
        return ResultBuilder.buildSuccess(null);
    }



}
